﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunctionalLayer
{
    /// <summary>
    /// This class is used to get the advise speed 
    /// </summary>
    public class SpeedAdvisor
    {
        public SpeedAdvisor(){}

        /// <summary>
        /// Calculated the minimum speed that is needed to finish on time
        /// </summary>
        /// <param name="distanceTravelled">The total distance traveld </param>
        /// <param name="TimeLeft"></param>
        /// <returns></returns>
        public double Calculate(double distanceTravelled, TimeSpan TimeLeft)
        {
            double distanceLeft = (ConfigSingleton.Settings.LapDistance * ConfigSingleton.Settings.Laps) - distanceTravelled;
            double secondsLeft = TimeLeft.Minutes * 60 + TimeLeft.Seconds;

            var advise = (distanceLeft / secondsLeft) * 3600;
            if (advise < 0)
                return 0;
            return advise;
        }

    }
}
